import 'package:situation/app/theme/app_theme.dart';
import 'package:situation/widgets/mk_card_container.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class UserPrivacyPermissionPage extends StatefulWidget {
  const UserPrivacyPermissionPage({Key? key}) : super(key: key);

  @override
  State<UserPrivacyPermissionPage> createState() =>
      _UserPrivacyPermissionPageState();
}

class _UserPrivacyPermissionPageState extends State<UserPrivacyPermissionPage> {
  final controller = Get.find<UserPrivacyPermissionController>();
  final state = Get.find<UserPrivacyPermissionController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TDNavBar(
        title: '个人信息保护设置',
      ),
      body: Column(
        children: [ _buildPermission()],
      ),
    );
  }


  _buildPermission() {
    return MkCardContainer(
      padding: EdgeInsets.symmetric(horizontal: AppTheme.iDefaultPadding / 2),
      margin: EdgeInsets.symmetric(
          horizontal: AppTheme.iDefaultPadding,
          vertical: AppTheme.iDefaultPadding / 2),
      borderRadius: AppTheme.iBorderRadius,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          TDCell(
            title: '存储空间信息',
            description: '帮助你管理发布、保存、修改信息等功能，关闭后，将不能访问、读取相册，存储空间内的信息',
            style: TDCellStyle(
              padding: EdgeInsets.all(10),
              descriptionStyle: TextStyle(color: Colors.grey, fontSize: 12),
            ),
            onClick: (TDCell c) {
              controller.requestPermission(Permission.storage);
            },
            rightIconWidget:
                Obx(() => state.storageStatus ? Text('已开启') : Text('去设置')),
          ),
          TDCell(
            title: '音视频信息（摄像头）',
            description: '帮助你管理、授权通过录制，拍摄等方式收集音视频信息，关闭后，将不能采集音视频信息',
            style: TDCellStyle(
              padding: EdgeInsets.all(10),
              descriptionStyle: TextStyle(color: Colors.grey, fontSize: 12),
            ),
            arrow: true,
            onClick: (TDCell c) {
              controller.requestPermission(Permission.camera);
            },
            rightIconWidget:
                Obx(() => state.caremaStatus ? Text('已开启') : Text('去设置')),
          ),
          TDCell(
            title: '音视频信息（麦克风）',
            description: '帮助你管理、授权麦克风用于发布音视频，关闭后，将不能采集语音信息',
            style: TDCellStyle(
              padding: EdgeInsets.all(10),
              descriptionStyle: TextStyle(color: Colors.grey, fontSize: 12),
            ),
            arrow: true,
            onClick: (TDCell c) {
              controller.requestPermission(Permission.microphone);
            },
            rightIconWidget:
                Obx(() => state.audioStatus ? Text('已开启') : Text('去设置')),
          ),
          TDCell(
            title: '精确位置信息',
            description: '关闭后，将不再收集你的GPS等精确位置信息，仅通过IP等定位大致的位置保障基本的业务功能',
            style: TDCellStyle(
              padding: EdgeInsets.all(10),
              descriptionStyle: TextStyle(color: Colors.grey, fontSize: 12),
            ),
            arrow: true,
            onClick: (TDCell c) {
              controller.requestPermission(Permission.location);
            },
            rightIconWidget:
                Obx(() => state.locationStatus ? Text('已开启') : Text('去设置')),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<UserPrivacyPermissionController>();
    super.dispose();
  }
}
